#include "common.hpp"


#define SEND_TIMES 10 //服务端发送向客户端发送消息的次数

int main()
{
    createNamedPipe();
    int fd = open(PIPE_NAME, O_WRONLY);//当前进程打开管道文件后 会等待另一个进程打开管道文件才会继续向下执行
    assert(fd != -1);
    int count = SEND_TIMES;
    int forever = count <= 0 ? 1 : 0;
    while (count > 0 || forever)
    {
        char buffer[1024];
        cout << "please say: ";
        fgets(buffer, sizeof buffer, stdin);
        buffer[strlen(buffer) - 1] = 0;
        write(fd, buffer, strlen(buffer));
        if (!forever)
            count--;
    }
    removeNamedPipe();
    return 0;
}
